<?php
namespace PsiFramework\Classes\Util\Parameters\Object;

import("Classes.Util.Parameters.Object.Operations.Elements.OperationObject");
import("Classes.Util.Parameters.Object.Operations.Elements.OperationClause");
import("Classes.Util.Parameters.Object.Operations.Elements.OperationSimpleClause");
import("Classes.Util.Parameters.Object.Operations.Elements.OperationMultipleClause");
import("Classes.Util.Parameters.Object.Operations.Elements.OperationColumn");

use \PsiFramework\Classes\Util\Parameters\Object\Operations\Elements\OperationObject;
use \PsiFramework\Classes\Util\Parameters\Object\Operations\Elements\OperationClause;

/**
 * PsiFramework
 * Php Simple Framework
 *
 * @author Rémi San
 * @version beta
 */

/**
 * The Trigger class is the class to manage object parameters operations
 *
 * @package Util.Parameters.Object
 */
abstract class Operation
{

    protected /*string*/            $_type ;
    protected /*OperationObject[]*/ $_objects ;
    protected /*OperationClause*/   $_whereClause ;

    public function __construct(
        /*string*/ $type=null,
        /*OperationObject[]*/ $objects=array(),
        OperationClause $whereClause=null
    )
    {
        $this->_type = $type ;
        $this->_objects = $objects ;
        $this->_whereClause = $whereClause ;
    }

    public function getType()
    {
        return $this->_type ;
    }

    public function setType(/*string*/ $type)
    {
        $this->_type = $type ;
    }

    public function getObjects()
    {
        return $this->_objects ;
    }

    public function setObjects(/*OperationObject[]*/ $objects)
    {
        $this->_objects = $objects ;
    }

    public function getObject(/*mixed*/ $index)
    {
        return $this->_objects[$index] ;
    }

    public function getDefaultObject()
    {
        return $this->_objects[0] ;
    }

    public function getObjectByAlias(/*string*/ $alias)
    {
        $object = null ;

        foreach ($this->_objects as $obj) {
            if ($obj->getAlias() == $alias) {
                $object = $obj ;
                break ;
            }
        }

        if (is_null($object)) {
            $object = $this->getDefaultObject();
        }

        return $object ;
    }

    public function addObject(OperationObject $object)
    {
        if (is_null($this->_objects)) {
            $this->_objects = array();
        }
        $this->_objects[] = $object ;
    }

    public function getWhereClause()
    {
        return $this->_whereClause ;
    }

    public function setWhereClause(OperationClause $whereClause)
    {
        $this->_whereClause = $whereClause ;
    }
}
